// components/movable-menu/movable-menu.js
Component({
        /**
         * 组件的属性列表
         */
        properties: {
                multipleSlots: true // 在组件定义时的选项中启用多slot支持
        },

        /**
         * 组件的初始数据
         */
        data: {
                x: 0,
                y: 0,
                statusBarHeight: 0,
                windowWidth: 0,
                windowHeight: 0,
                menuVisible: false,
                menuY: 0,
                menuAnimation: 'hide',
                publishAnimation: 'hide',
                publishVisible: false,
        },

        lifetimes: {
                attached() {
                        const that = this;
                        const windowInfo = wx.getWindowInfo();
                        that.setData({
                                windowWidth: windowInfo.windowWidth,
                                windowHeight: windowInfo.windowHeight,
                                statusBarHeight: windowInfo.statusBarHeight,
                                x: windowInfo.windowWidth,
                                y: (windowInfo.windowHeight - (windowInfo.statusBarHeight + 200))
                        });
                }
        },

        /**
         * 组件的方法列表
         */
        methods: {
                handleMenuVisible() {
                        const that = this;
                        that.setData({
                                menuAnimation: !that.data.menuVisible ? 'show' : 'hide'
                        });
                        if(that.data.menuVisible) {
                                setTimeout(function(){
                                        that.setData({
                                                menuVisible: false
                                        }); 
                                }, 400);
                        }else{
                                that.setData({
                                        menuVisible: true
                                });
                        }
                },
                handlePublishVisible() {
                        const that = this;
                        that.setData({
                                publishAnimation: !that.data.publishVisible ? 'show' : 'hide'
                        });
                        if(that.data.publishVisible) {
                                setTimeout(function(){
                                        that.setData({
                                                publishVisible: false
                                        }); 
                                }, 400);
                        }else{
                                that.setData({
                                        publishVisible: true
                                });
                        }
                },
                handleJump(e) {
                        const that = this;
                        const page = e.currentTarget.dataset.page;
                        if (page.indexOf('/pages/community-publish/community-publish') !== -1) {
                                that.handlePublishVisible();
                                wx.navigateTo({
                                        url: page,
                                })
                        }
                }
        }
})